//
//  NewBarButtonItem.swift
//  新浪微博项目
//
//  Created by 王炯 on 16/7/20.
//  Copyright © 2016年 王炯. All rights reserved.
//

import UIKit

class NewBarButtonItem: UIBarButtonItem
{

    init(title:String?,imageStr:String?,target: AnyObject?, action: Selector)
    {
        super.init()
        
        let button:UIButton = UIButton()
        
        //如果有title
        if let wordtitle = title
        {
            button.setTitle(wordtitle, forState: UIControlState.Normal)
            
            button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
            button.titleLabel?.font = UIFont.systemFontOfSize(15)
        }
        
        //如果有imageStr
        if let imageString = imageStr
        {
            button.setImage(UIImage(named: imageString), forState: UIControlState.Normal)
        }
        
        //设置点击事件
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        //设置button自适应
        button.sizeToFit()
        
        //设置button为CustomView
        self.customView = button
    }
    
    required init?(coder aDecoder: NSCoder)
    {
        fatalError("init(coder:) has not been implemented")
    }
    
}
